<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约列表管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">



                    <div class="filter-container">
                        <el-date-picker
                                @change="selectByDate"
                                v-model="value.orderDate"
                                type="datetimerange"
                                :picker-options="pickerOptions2"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                align="right">
                        </el-date-picker>
                        <el-select v-model="value.orderType" placeholder="请选择" @change="selectByOrderType">
                            <el-option
                                    v-for="item in options01"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                        <el-select v-model="value.orderStatus" placeholder="请选择" @change="selectByOrderStatus">
                            <el-option
                                    v-for="item in options02"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>

                        <el-input placeholder="会员姓名/手机号" v-model="value.orderString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="search()" class="dalfBut">查询</el-button>

                        <el-button type="primary" class="butT" @click="handleCreate()">预约</el-button>
                        <el-button type="primary" class="butT" @click="handleClear()">清除</el-button>
                    </div>

                    <!--列表数据dataList-->
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="member_name" label="会员姓名" align="center"></el-table-column>
                        <el-table-column prop="phoneNumber" label="电话号码" align="center"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center">
                            <template slot-scope="scope" style="width:42%">
                                <!--<span v-model="scope.row.orderStatus" prop="orderStatus"></span>-->
                                {{scope.row.orderStatus}}
                            <el-switch
                                    v-model="scope.row.orderStatus"
                                    active-color="#13ce66"
                                    inactive-color="#ff4949"
                                    active-value="未到诊"
                                    inactive-value="已完成"
                                    @change="changeOrderStatus(scope.row)"
                            >
                            </el-switch>
                            </template>
                        </el-table-column>

                        <el-table-column prop="setmeal_name" label="套餐名称" align="center"></el-table-column>

                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            background
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>


                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号码" prop="phone">
                                                        <el-input v-model="addData.phoneNumber"/>
                                                    </el-form-item>
                                                </el-col>

                                                <el-col :span="12">
                                                    <el-form-item label="预约日期">
                                                        <el-date-picker
                                                                v-model="addData.orderDate"
                                                                type="date"
                                                                placeholder="选择日期">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="姓名">
                                                        <el-input v-model="addData.name"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
									<div class="checkScrol">
                                        <table class="datatable">
                                            <thead>
								<tr>
                                                <th>选择</th>
                                                <th>套餐编码</th>
                                                <th>套餐名称</th>
                                                <th>套餐说明</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr v-for="c in tableData">
                                                <td>
                                                    <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                                </td>
                                                <td><label :for="c.id">{{c.code}}</label></td>
                                                <td><label :for="c.id">{{c.name}}</label></td>
                                                <td><label :for="c.id">{{c.remark}}</label></td>
                                            </tr>
                                            </tbody>
                                        </table>
									</div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="编辑预约" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名">
                                                        <el-input v-model="formData.member_name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约日期">
                                                        <el-date-picker
                                                                v-model="formData.orderDate"
                                                                type="date"
                                                                placeholder="选择日期">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约类型">
                                                        <el-select v-model="formData.orderType" placeholder="请选择">
                                                            <el-option
                                                                    v-for="item in options01"
                                                                    :key="item.value"
                                                                    :label="item.label"
                                                                    :value="item.value">
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约状态">
                                                        <el-select v-model="formData.orderStatus" placeholder="请选择">
                                                            <el-option
                                                                    v-for="item in options02"
                                                                    :key="item.value"
                                                                    :label="item.label"
                                                                    :value="item.value">
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>

                                    <el-tab-pane label="检查组信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>项目编码</th>
                                                    <th>项目名称</th>
                                                    <th>项目说明</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="c in tableData">
                                                    <td>
                                                        <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                                    </td>
                                                    <td><label :for="c.id">{{c.code}}</label></td>
                                                    <td><label :for="c.id">{{c.name}}</label></td>
                                                    <td><label :for="c.id">{{c.remark}}</label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                    value1: true,
                    value2: true,
                value8: true,
                    pickerOptions2: {},
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:10,
                    total:100,
                    queryString:null,
                },
                dataList: [],//列表数据
                formData:{
                    orderDate:'',
                    orderType:'',
                    orderStatus:'',
                    memberId:''
                },//表单数据
                tableData:[],//新增和编辑表单中对应的检查项列表数据
                setmealIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
                options01: [{
                    value: '微信预约',
                    label: '微信预约'
                }, {
                    value: '电话预约',
                    label: '电话预约'
                }],
                options02:[{
                    value: '未到诊',
                    label: '未到诊'
                }, {
                    value: '已完成',
                    label: '已完成'
                }],
                value:{
                    orderDate:'',
                    orderType:'',
                    orderStatus: '',
                    orderString:''
                },
                addData:{},
                // rules:{
                //   phone:[{required: true, message: '手机号码为必填项', trigger: 'blur' }]
                // }
                oldDate:[],
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();
            },
            methods: {
                //按钮改变状态
                changeOrderStatus(row){
                    axios.post("/orderController/changeOrderStatus.do?id="+row.id).then((response)=>{
                        if(response.data.flag){
                        }
                    })
                },
                //清除按钮
                handleClear(){
                    this.pagination.currentPage=1;
                    this.value={}
                    this.dataList=''
                    this.findPage();
                },
                // 根据预约状态查询
                selectByOrderStatus(){
                    this.pagination.currentPage=1;
                    var param={
                        currentPage:this.pagination.currentPage,    //页码
                        pageSize:this.pagination.pageSize,          //每页显示的记录数
                        queryString:this.value.orderStatus//查询条件
                    }
                    axios.post("/orderController/findByOrderStatus.do",param).then((response)=>{
                        this.pagination.total=response.data.total;
                        this.dataList=response.data.rows;
                    })

                },
                //根据预约类型查询
                selectByOrderType(){
                    this.pagination.currentPage=1;
                    var param={
                        currentPage:this.pagination.currentPage,    //页码
                        pageSize:this.pagination.pageSize,          //每页显示的记录数
                        queryString:this.value.orderType//查询条件
                    }
                    axios.post("/orderController/findByOrderType.do",param).then((response)=>{
                        this.pagination.total=response.data.total;
                        this.dataList=response.data.rows;
                    })
                },
                //根据日期查询
                selectByDate(){
                    this.pagination.currentPage=1;
                    var param={
                        currentPage:this.pagination.currentPage,    //页码
                        pageSize:this.pagination.pageSize,          //每页显示的记录数
                        orderDate:this.value.orderDate  //查询条件
                    }
                    axios.post("/orderController/findByDate.do",param).then((response)=>{
                        this.pagination.total=response.data.total;
                        this.dataList=response.data.rows;
                    })
                },
                //处理查询
                search(){
                    this.pagination.currentPage=1;
                    var param={
                        currentPage:this.pagination.currentPage,    //页码
                        pageSize:this.pagination.pageSize,          //每页显示的记录数
                        queryString:this.value.orderString  //查询条件
                    }
                    axios.post("/orderController/findByOrderString.do",param).then((response)=>{
                        this.pagination.total=response.data.total;
                        this.dataList=response.data.rows;
                    })
                },
                // 编辑
                handleEdit() {
                     // console.assert( row.id);
                    // window.alert(row.id)
                    axios.post("/orderController/edit.do?setmealId="+this.setmealIds,this.formData).then((res)=>{
                        if (res.data.flag){
                            //修改成功
                            this.$message({
                                type:'success',
                                message:res.data.message,
                                center:true
                            })
                            // 分页查询
                            this.findPage();
                        }else {
                            //修改失败
                            this.$message({
                                type:'error',
                                message:res.data.message,
                                center:true
                            });
                        }
                    }).finally(()=>{
                        //关闭编辑窗口
                        this.dialogFormVisible4Edit=false;
                    });
                },
                //添加
                handleAdd () {
                    // this.$refs['addForm'].validate((valid)=>{
                    //     if(valid){
                            //发送AJAX请求将模型数据提交到后台处理
                            //1.先注册会员(添加会员功能)，返回会员id
                            axios.post("/orderController/add4Order.do",this.addData).then((response)=>{
                                if(response.data.flag){
                                    this.addData.memberId = response.data.data;
                                    console.log(response.data.data);
                                    //2.添加预约套餐
                                    axios.post("/orderController/add.do?setmealIds="+this.setmealIds,this.addData).then((res)=>{
                                        if (res.data.flag){
                                            //添加成功，弹出成功提示
                                            this.$message({
                                                type:'success',
                                                message:res.data.message,
                                                center:true,
                                            })
                                            this.findPage()
                                        } else {
                                            //添加失败，弹出错误提示
                                            this.$message({
                                                type:'error',
                                                message:res.data.message,
                                                center:true
                                            })
                                        }
                                    })
                                }
                            }).finally(()=>{
                                //关闭新增窗口
                                this.dialogFormVisible=false;
                                //分页查询
                                this.findPage();
                            })
                        // }else{
                        //     //校验不通过，提示错误信息
                        //     this.$message.error("表单校验失败！")
                        //     return false;
                        // }
                    // })
                },
                //分页查询
                findPage() {
                    //分页参数
                    var param={
                        currentPage:this.pagination.currentPage,    //页码
                        pageSize:this.pagination.pageSize,          //每页显示的记录数
                        queryString:this.pagination.queryString     //查询条件
                    }
                    //发送Ajax请求
                    axios.post("/orderController/findPage.do",param).then((res)=>{
                        //设置总记录数，分页才能正常显示
                        this.pagination.total=res.data.total;
                        //显示分页数据
                        this.dataList=res.data.rows;
                    })
                },
                // 重置表单
                resetForm() {
                    this.formData={};
                },
                // 弹出添加窗口
                handleCreate() {
                    //弹出添加窗口
                    this.dialogFormVisible=true;
                    //重置表单
                    // this.$nextTick(()=>{
                    //     this.$refs['addForm'].clearValidate(()=>{});
                    // });
                    this.addData={};
                    //让第一个选项卡被选中
                    this.activeName='first';
                    //重置复选框
                    this.setmealIds=[];
                    //发送Ajax请求查询所有检查项信息
                    axios.get("/setmeal/getAllSetmeal.do").then((res)=>{
                        if (res.data.flag){
                            //查询成功
                            //将检查项列表数据赋值给模型数据用于将页面展示
                            this.tableData=res.data.data;
                        } else {
                            this.$message({
                                type:'error',
                                message:res.data.message,
                                center:true
                            });
                        }
                    })

                },
                // 弹出编辑窗口
                handleUpdate(row) {
                    //显示编辑窗口
                    this.dialogFormVisible4Edit=true;
                    //让第一个选项卡被选中
                    this.activeName='first';
                    // //1.数据回显,查询预约信息
                    this.formData.id = row.id;
                    axios.post("/orderController/findById.do?orderId="+ row.id).then((res=>{
                        if (res.data.flag){
                            //查询检查组成功
                            //检查组基本信息回填
                            this.formData.member_name=res.data.data.member
                            this.formData.orderDate=res.data.data.orderDate
                            this.formData.orderType=res.data.data.orderType
                            this.formData.orderStatus=res.data.data.orderStatus
                            this.oldDate=res.data.data.orderDate
                        }else {
                            //提示失败
                            this.$message({
                                type:'error',
                                message:res.data.message,
                                center:true
                            });
                        }
                    }));
                    //2.发送Ajax请求查询已预约套餐
                    axios.get("/setmeal/getAllSetmeal.do").then((res)=>{
                        if (res.data.flag){
                            //查询成功
                            //将检查项列表数据赋值给模型数据用于将页面展示
                            this.tableData=res.data.data;
                            //3.再次发送AJAX请求查询检查组关联的检查项的id集合
                            axios.get("/orderController/findSetmealIdsByOrderId.do?orderId="+row.id).then((res)=>{
                                if (res.data.flag){
                                    this.$message({
                                        type:'success',
                                        message:res.data.message,
                                        center:true
                                    });
                                    //回显检查项
                                    this.setmealIds=res.data.data;
                                }
                            });
                        } else {
                            this.$message({
                                type:'error',
                                message:res.data.message,
                                center:true
                            });
                        }
                    });

                },
                //切换页码
                handleCurrentChange(currentPage) {
                    //更改模型数据中的当前页
                    this.pagination.currentPage = currentPage;
                    //分页查询
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    //弹出确认框
                    this.$confirm('确定要删除吗？这会导致所有的检查项也会被移除','提示',{
                        confirmButtonText:'确定',
                        cancelButtonText:'取消',
                        type:'warning'
                    }).then(()=>{
                        //发送ajax请求，将id传到controller
                        axios.get("/orderController/delete.do?id="+row.id).then((res)=>{
                            if (res.data.flag){
                                //删除成功
                                this.$message({
                                    type:'success',
                                    message:res.data.message,
                                    center:true
                                });
                            } else {
                                //删除失败
                                this.$message({
                                    type:'error',
                                    message:res.data.message,
                                    center:true
                                });
                            }
                        }).finally(()=>{
                            //无论成功失败都要经行分页查询
                            //分页查询
                            this.findPage();
                        });

                    }).catch(()=>{
                        this.$message({
                            type:'info',
                            message:'操作已取消',
                            center:true
                        });
                    });
                }
            }
        })
    </script>
</html>
